function ga2Q(popsize,dimension,stringlength,x_bound,matlast,mat2dpoints,I,Im)%default pm = 0.05
%popsize=200;dimension=2;stringlength=8;x_bound=[0,1;0,13];
pm=0.05; 
%se generan universos deacuerdo al numero de variables
pop=encodiQ(popsize,stringlength,dimension); 

for y=1:dimension
    pop{y}=decoding(pop{y},stringlength,dimension,x_bound,matlast,mat2dpoints,I,Im);
    A=pop{y};
    [choice_number(y,1),choice_k(y,1)]=max(A(:,stringlength*dimension+1)) ;
end

%fprintf('pase');
%choice=pop(choice_k,:)

choice_k(y,1)

%[choice_number,choice_k]=max(pop(:,stringlength*dimension+1));
for j=1:dimension
    poptemp=pop{j};
 choice(j,:)=poptemp(choice_k(j,1),:)
end
%fprintf('pase');
for i=1:20
    %fprintf('pase iteracion');
    new_pop=cross_over(pop{1},popsize,stringlength,dimension); 
    new_pop2=cross_over(pop{2},popsize,stringlength,dimension);
    %fprintf('pase crosover');
    popp=mutation(new_pop,stringlength,dimension,pm); 
    popp2=mutation(new_pop2,stringlength,dimension,pm);
    size(pop,1);
    
    %fprintf('pase');
    
    popp=decoding(popp,stringlength,dimension,x_bound,matlast,mat2dpoints,I,Im); 
    popp2=decoding(popp2,stringlength,dimension,x_bound,matlast,mat2dpoints,I,Im);
    
    [number,k]=max(popp(:,stringlength*dimension+1));
    [number2,k2]=max(popp2(:,stringlength*dimension+1));
        
        if choice_number(1,1)<number 
            choice_number(1,1)=number; 
            choice_k(1,1)=k; 
            choice(1,:)=popp(choice_k(1,1),:); 
        end
        if choice_number<number2 
            choice_number(2,1)=number2; 
            choice_k(2,1)=k2; 
            choice(2,:)=popp2(choice_k(2,1),:); 
        end
     %interferencia entre universos -----
     [childQ]=cross_overQ(choice,popsize,stringlength,dimension);
     childQ=decoding(childQ,stringlength,dimension,x_bound,matlast,mat2dpoints,I,Im);
     %childQ(2,:)=decoding(childQ(2,:),stringlength,dimension,x_bound,matlast,mat2dpoints,I,Im);
     %------------------------------------
    popp=selection(popp,popsize,stringlength,dimension);
    popp2=selection(popp2,popsize,stringlength,dimension);
    
    
    [number,m]=sort(popp(:,stringlength*dimension+1)); 
    [number2,m2]=sort(popp2(:,stringlength*dimension+1));
    
    popp(m(1,1),:)=choice(1,1);
    popp(m(2,1),:)=childQ(1,:);
    popp2(m2(1,1),:)=choice(2,1);
    popp2(m2(2,1),:)=childQ(2,:);
    
end

if max(popp(:,stringlength*dimension+1))>max(popp2(:,stringlength*dimension+1))
    [value,x]=result(popp,stringlength,dimension,x_bound,matlast,mat2dpoints,I,Im)
else
    [value,x]=result(popp2,stringlength,dimension,x_bound,matlast,mat2dpoints,I,Im)
end